package Insertion;

import java.util.Arrays;

public class Insertion2 {
    public static void main(String[] args) {
        Integer[] arr = {6, 5, 4, 2, 1, 3};
        Insertion2.sort(arr);
        System.out.println(Arrays.toString(arr));
    }

    public static void sort(Comparable[] a) {
        for (int i = 1; i < a.length; i++) {
            for (int j = i; j > 0; j--) {
                if (greater(a[j - 1], a[j])) {
                    exch(a, j - 1, j);
                } else {
                    break;
                }
            }
        }
    }

    public static boolean greater(Comparable a, Comparable b) {
        return a.compareTo(b) > 0;
    }

    public static void exch(Comparable[] a, int i, int j) {
        Comparable temp;
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
}
